package com.sixth.volunteerservicesystem.Controller.theoryback;

import com.sixth.volunteerservicesystem.Service.LearnTheoryservice;
import com.sixth.volunteerservicesystem.Service.Videoservice;
import com.sixth.volunteerservicesystem.domain.Theory;
import com.sixth.volunteerservicesystem.domain.Video;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class theoryback {
    @Resource
    private JdbcTemplate jdbcTemplate;
    @Autowired
    LearnTheoryservice learnTheoryservice;
    @Autowired
    Videoservice videoservice;


    @GetMapping("/theoryback")
    public String list(Model model) {
        List<Theory> theory = learnTheoryservice.list();
        List<Video> videos = videoservice.list();
        model.addAttribute("videos", videos);
        model.addAttribute("theory", theory);
        return "learntheory/theoryback";
    }
    @GetMapping("/theorydetailback/{id}")
    public String theorydetailback(@PathVariable("id")int id, Model model) {
        Theory theory = learnTheoryservice.getone(id);
        model.addAttribute("theory",theory);
        return "learntheory/theorydetailback";
    }
    @GetMapping("/delete/{id}")
    public String delete(@PathVariable("id")int id, Model model) {
        learnTheoryservice.delete(id);
        return "redirect:/theoryback";
    }
    @GetMapping("/deletevideo/{id}")
    public String deletevideo(@PathVariable("id")int id, Model model) {
        videoservice.delete(id);
        return "redirect:/theoryback";
    }
}